package com.teamcenter.rac.massupdate.databinding;

import org.eclipse.ui.views.properties.IPropertySource;

import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.massupdate.model.UpdateJobModel;
import com.teamcenter.rac.massupdate.utils.MassUpdateHelper;
import com.teamcenter.rac.massupdate.utils.SourceHelper;
import com.teamcenter.rac.util.AdapterUtil;

public class ChangeObjectChangeObservable
  extends AbstractModelObservable
{
  public void doSetValue(Object paramObject)
  {
    super.doSetValue(paramObject);
    final Object localObject = paramObject;
    AbstractAIFOperation local1 = new AbstractAIFOperation()
    {
      public void executeOperation()
        throws Exception
      {
        UpdateJobModel localUpdateJobModel = ChangeObjectChangeObservable.this.getUpdateJobModel();
        IPropertySource localIPropertySource1 = (IPropertySource)localObject;
        if (localIPropertySource1 != null)
        {
          TCSession localTCSession = (TCSession)getSession();
          TCComponent localTCComponent1 = SourceHelper.getAssociatedComponent(localIPropertySource1, localTCSession);
          if (localTCComponent1 != null)
          {
            TCComponentItemRevision localTCComponentItemRevision1 = (TCComponentItemRevision)AdapterUtil.getAdapter(localTCComponent1, TCComponentItemRevision.class);
            if ((localTCComponentItemRevision1 != null) && (MassUpdateHelper.isChangeItemRevision(localTCComponentItemRevision1)))
            {
              boolean bool1 = false;
              boolean bool2 = false;
              IPropertySource localIPropertySource2 = null;
              localTCComponentItemRevision1.clearCache("IMAN_reference");
              TCComponent localTCComponent2 = MassUpdateHelper.getMarkupObject(localTCComponentItemRevision1);
              localIPropertySource2 = (IPropertySource)AdapterUtil.getAdapter(localTCComponent2, IPropertySource.class);
              IPropertySource localIPropertySource3 = localUpdateJobModel.getTargetPart();
              Object localObject2;
              if (localIPropertySource3 != null)
              {
            	  TCComponent localObject1 = SourceHelper.getAssociatedComponent(localIPropertySource3, localTCSession);
                if (localObject1 != null)
                {
                  localObject2 = (TCComponentItemRevision)AdapterUtil.getAdapter(localObject1, TCComponentItemRevision.class);
                  if (localObject2 != null) {
                    bool2 = MassUpdateHelper.isProblemFolderAccessible(localTCComponentItemRevision1, (TCComponent)localObject2);
                  }
                }
              }
              Object localObject1 = localUpdateJobModel.getReplacementPart();
              if (localObject1 != null)
              {
                localObject2 = SourceHelper.getAssociatedComponent((IPropertySource)localObject1, localTCSession);
                if (localObject2 != null)
                {
                  TCComponentItemRevision localTCComponentItemRevision2 = (TCComponentItemRevision)AdapterUtil.getAdapter(localObject2, TCComponentItemRevision.class);
                  if (localTCComponentItemRevision2 != null) {
                    bool1 = MassUpdateHelper.isSolutionFolderAccessible(localTCComponentItemRevision1, localTCComponentItemRevision2);
                  }
                }
              }
              localUpdateJobModel.setProblemFolderAccessible(bool2);
              localUpdateJobModel.setSolutionFolderAccessible(bool1);
              localUpdateJobModel.setMarkupObject(localIPropertySource2);
              localUpdateJobModel.setImpactedPartsUpToDate(false);
              if ((!bool2) && (localUpdateJobModel.isSaveTargetPartInFolder())) {
                localUpdateJobModel.setSaveTargetPartInFolder(false);
              }
              if ((!bool1) && (localUpdateJobModel.isSaveReplacementPartInFolder())) {
                localUpdateJobModel.setSaveReplacementPartInFolder(false);
              }
              return;
            }
          }
        }
        localUpdateJobModel.setProblemFolderAccessible(false);
        localUpdateJobModel.setSolutionFolderAccessible(false);
        localUpdateJobModel.setMarkupObject(null);
        localUpdateJobModel.setImpactedPartsUpToDate(false);
      }
    };
    getTCSession().queueOperation(local1);
  }
}

